//
//  ContentView.swift
//  Chatup
//
//  Created by op on 2023/10/15.
//

import SwiftUI

struct CustomTabItemView: View {
    let imageName: String
    let tabText: String
    let selected: Bool
    
    var body: some View {
        VStack {
            Image(selected ? "\(imageName)_sele" : imageName)
            Text(tabText)
        }
        .imageScale(.large)
        .font(.footnote)
    }
}

struct MsgItem:Equatable,Identifiable{
    let id = UUID()
    let text:String
    init(text: String) {
        self.text = text
    }
    
    static func == (lhs: MsgItem, rhs: MsgItem) -> Bool {
        return lhs.id == rhs.id && lhs.text == rhs.text
    }
}

struct ContentView: View {
    @State private var selection: Tab = .second
    @State var item:MsgItem = .init(text: "")
    @State var historyItemRoleId:Int = 0
    @State var showvip = false
    enum Tab {
        case first
        case second
        case third
    }
    
    var body: some View {
//        NavigationView(content: {
            TabView(selection: $selection) {
                NavigationView {
                    AssistantsView(section: $selection, item: $item)
                }
                .navigationViewStyle(StackNavigationViewStyle())
                .tabItem {
                    CustomTabItemView(
                        imageName: "icon_assi",
                        tabText: String.i18nText("tab_assistants"),
                        selected: selection == .first
                    )
                }
                .tag(Tab.first)
                
                NavigationView {
                    HomePageView(section: $selection, item: $item, historyItemRoleId: $historyItemRoleId)
                }
                .navigationViewStyle(StackNavigationViewStyle())
                .tabItem {
                    CustomTabItemView(
                        imageName: "icon_homepage",
                        tabText: String.i18nText("tab_chat"),
                        selected: selection == .second
                    )
                }
                .tag(Tab.second)
                
                NavigationView {
                    HistoryView(section: $selection, historyItemRoleId: $historyItemRoleId)
                }
//                .navigationViewStyle(StackNavigationViewStyle())
                .tabItem {
                    CustomTabItemView(
                        imageName: "icon_character",
                        tabText: String.i18nText("tab_history"),
                        selected: selection == .third
                    )
                }
                .tag(Tab.third)
            }
            .tabViewStyle(DefaultTabViewStyle())
            .onAppear{
//                if UserDefaults.standard.bool(forKey: "kHasSeenGuide") {
//                    showvip.toggle()
//                }
            }.environment(\.locale, .init(identifier: NSLocale.current.identifier))
//            .fullScreenCover(isPresented: $showvip, content: {
//                VipView()
//            })
//        })
    }
}

#Preview {
    ContentView()
}
